package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/v1/dictoption")
@RestController
public class DictOptionController {
     @Autowired
    DictOptionService dictOptionService;

     @GetMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery){
         log.debug("查询字典项:dictOptionQuery={}",dictOptionQuery);
         List<DictOptionVO> list =dictOptionService.selectDictOption(dictOptionQuery);
         return JsonResult.ok(list);
     }
    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionSaveParam dictOptionSaveParam){
        log.debug("保存字典项:dictOptionSaveParam={}",dictOptionSaveParam);
        dictOptionService.saveDictOption(dictOptionSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("删除字典项:id={}",id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }
    //定义一个根据字典code查此字典对应的所有字典项的方法
    @GetMapping("select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("根据字典code查询字典项:code={}",code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }

}
